<template>
    <div class="app-body">
        <div class="coupon-search-bar">
            <div class="search-bar">
                <i class="iconfont icon-search3"></i>
                <input v-on:keyup.13="onKeyup($event)" placeholder="输入关键词或淘宝标题" :value="keywords"/>
            </div>
        </div>
        <div class="search-result">
            <div class="sg-list">
                <div class="sg-list-header">
                    <ul>
                        <li v-for="item in goodsList">
                            <a :href="item.coupon_click_url">
                                <div class="img">
                                    <img class="sg-img-responsive" :src="item.pict_url"/>
                                </div>
                                <div class="info">
                                    <p class="name">{{item.title}}</p>

                                    <div class="original-price">
                                        <s>原价：￥{{item.zk_final_price}}</s>
                                    </div>
                                    <div class="" style="position: relative">
                                        <span class="price">￥{{item.zk_final_price}}</span>
                                        <img v-if="item.coupon_status > 0" style="position: absolute;left: 5rem;width: 3rem" src="images/coupon_price.png">
                                        <span class="volume">销量    {{item.volume}}</span>
                                    </div>
                                </div>
                            </a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
    export default {
        data(){
            return {
                goodsList:[],
                keywords:this.$route.params.keywords,
            }
        },
        mounted(){
            this.search();
        },
        methods:{
            search(){
                let that                    =   this;
                if(this.keywords){
                    this.api.get('api/coupon/search',{params:{keywords:this.keywords}}).then(function(response){
                        if(response.status==200){
                            for(var i in response.data) {
                                that.goodsList.push(response.data[i]);
                            }
                        }
                    });
                }

            },
            onKeyup(e){
                this.keywords               =   e.target.value;
                this.search();
            }
        }
    }
</script>